package com.alliky.core.data;

import androidx.annotation.VisibleForTesting;

import com.alliky.core.api.ApiService;

import java.util.WeakHashMap;

import io.reactivex.Observable;

public class DataRepository extends BaseRepository {

    private volatile static DataRepository INSTANCE = null;

    private final ApiService mApiService;

    public DataRepository(ApiService apiService) {
        mApiService = apiService;
    }

    public static DataRepository getInstance(ApiService apiService) {
        if (INSTANCE == null) {
            synchronized (DataRepository.class) {
                if (INSTANCE == null) {
                    INSTANCE = new DataRepository(apiService);
                }
            }
        }
        return INSTANCE;
    }

    @VisibleForTesting
    public static void destroyInstance() {
        INSTANCE = null;
    }

    public Observable getBanner(WeakHashMap<String, Object> weakHashMap) {
        return mApiService.getBanner(weakHashMap);
    }

    public Observable getCategory(WeakHashMap<String, Object> weakHashMap) {
        return mApiService.getCategory(weakHashMap);
    }

    public Observable getHotGoods(WeakHashMap<String, Object> weakHashMap) {
        return mApiService.getHotGoods(weakHashMap);
    }

    public Observable getRecommendGoods(WeakHashMap<String, Object> weakHashMap) {
        return mApiService.getRecommendGoods(weakHashMap);
    }

    public Observable doLogin(WeakHashMap weakHashMap) {
        return mApiService.login(weakHashMap);
    }
}
